﻿using Common;
using DLL;
using NursingFormSystem.Model;
using SQLDLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NursingFormSystem
{
    public partial class UpdateCardNo : Form
    {
        public static Tb_User LoginUser;
        string userId = "";//工号
        //string userName = "";//用户名

        /// <param name="uNo">工号</param>
        /// <param name="uName">用户名</param>
        public UpdateCardNo(Tb_User loginUser)
        {
            InitializeComponent();
            LoginUser = loginUser;
            userId = LoginUser.UserId;//工号
            lblName.Text = LoginUser.UserName;//用户名
        }
        //重置
        private void btnReset_Click(object sender, EventArgs e)
        {
            txtCardNo.Text = "";
        }
        //保存
        private void btnSave_Click(object sender, EventArgs e)
        {
            string cardNo = txtCardNo.Text.Trim();
            if (string.IsNullOrEmpty(cardNo))
            {
                MessageBox.Show("请填写身份证号");
            }
            else
            {
                if (!string.IsNullOrEmpty(userId))
                {
                    string sql = string.Format("UPDATE P_Personnel SET IdCardNo='{0}' WHERE UserId='{1}'", cardNo, userId);
                    int result = SqlHelper.ExecuteNonQuery(Base.ConnNISStr, CommandType.Text, sql, null);
                    if (result > 0)
                    {
                        string sealImageBase64 = "";
                        string sealImageType = "";
                        string message = "";
                        ElectronicSignature es = new ElectronicSignature(LoginUser);
                        es.GetSealImageByCardNum(Base.ESIP, cardNo, out  sealImageBase64, out  sealImageType, out  message);
                        MessageBox.Show("修改成功");
                        this.Close();//关闭本窗口
                    }
                    else
                    {
                        MessageBox.Show("修改失败");
                    }
                }
            }
        }
    }
}
